#include "tmmotorworker.h"
#include "tmglobalctrl.h"

TMMotorWorker::TMMotorWorker(QObject *parent) : QObject(parent)
{

}
//===========head===========
void TMMotorWorker::slot_headEnable()
{
    try{
        m_prxMotor->HeadEnable(true,true);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_headPowerDown()
{
    try{
        m_prxMotor->HeadEnable(false,false);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_headLRInit()
{
    try{
        m_prxMotor->HeadLrInit();
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_headUDInit()
{
    try{
        m_prxMotor->HeadUdInit();
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_headLRAngle(int nAngle, int nSpeed)
{
    try{
        m_prxMotor->HeadLrAngle(nAngle,nSpeed);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_headUDAngle(int nAngle, int nSpeed)
{
    try{
        m_prxMotor->HeadUdAngle(nAngle,nSpeed);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}
//=============left hand===============
void TMMotorWorker::slot_handLEnable()
{
    try{
        m_prxMotor->HandLEnable(true,true);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handLPowerDown()
{
    try{
        m_prxMotor->HandLEnable(false,false);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handLSwingInit()
{
    try{
        m_prxMotor->HandLSwingInit();
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handLExpandInit()
{
    try{
        m_prxMotor->HandLExpandInit();
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handLSwingAngle(int nAngle, int nSpeed)
{
    try{
        m_prxMotor->HandLSwingAngle(nAngle,nSpeed);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handLExpandAngle(int nAngle, int nSpeed)
{
    try{
        m_prxMotor->HandLExpandAngle(nAngle,nSpeed);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}
//============right hand=============
void TMMotorWorker::slot_handREnable()
{
    try{
        m_prxMotor->HandREnable(true,true);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handRPowerDown()
{
    try{
        m_prxMotor->HandREnable(false,false);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handRSwingInit()
{
    try{
        m_prxMotor->HandRSwingInit();
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handRExpandInit()
{
    try{
        m_prxMotor->HandRExpandInit();
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handRSwingAngle(int nAngle, int nSpeed)
{
    try{
        m_prxMotor->HandRSwingAngle(nAngle,nSpeed);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_handRExpandAngle(int nAngle, int nSpeed)
{
    try{
        m_prxMotor->HandRExpandAngle(nAngle,nSpeed);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}
//============wheel===================
void TMMotorWorker::slot_wheelEnable()
{
    try{
        m_prxMotor->WheelEnable(true);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_wheelPowerDown()
{
    try{
        m_prxMotor->WheelEnable(false);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_wheelStop(bool bStopAbrupt)
{
    try{
        m_prxMotor->WheelStop(bStopAbrupt);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_wheelRunRotate(int nAngle, int nSpeed)
{
    try{
        m_prxMotor->WheelRotate(nAngle,nSpeed);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_wheelRun(int nDistance, int nSpeed)
{
    try{
        m_prxMotor->WheelRun(nDistance,nSpeed);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_wheelRunDiff(bool bLeft, int nLeftSpeed, bool bRight, int nRightSpeed)
{
    try{
        m_prxMotor->WheelRunDiff(bLeft,nLeftSpeed,bRight,nRightSpeed);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}
//==============sensor=================
void TMMotorWorker::slot_sensorBattery()
{
    QString m_data;
    std::vector<std::int32_t> m_strList;
    try{
        m_prxMotor->SensorBatteryValue(m_strList);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
    for(int i = 0;i < m_strList.size();i++){
        std::int32_t nData = m_strList.at(i);
        m_data.append(QString("[%1] %2\r\n").arg(i).arg(nData));
    }
    emit sig_sensorBatteryInfo(m_data);
}

void TMMotorWorker::slot_sensorSonic()
{
    QString m_data;
    std::vector<std::int32_t> m_strList;
    try{
        m_prxMotor->SensorSonicValue(m_strList);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
    for(int i = 0;i < m_strList.size();i++){
        std::int32_t nData = m_strList.at(i);
        m_data.append(QString("[%1] %2\r\n").arg(i).arg(nData));
    }
    emit sig_sensorSonicInfo(m_data);
}

void TMMotorWorker::slot_sensorInfrared()
{
    QString m_data;
    std::vector<std::int32_t> m_strList;
    try{
        m_prxMotor->SensorInfraredValue(m_strList);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
    for(int i = 0;i < m_strList.size();i++){
        std::int32_t nData = m_strList.at(i);
        m_data.append(QString("[%1] %2\r\n").arg(i).arg(nData));
    }
    emit sig_sensorInfraredInfo(m_data);
}

void TMMotorWorker::slot_sensorWheel()
{
//    QString m_data;
//    std::vector<std::int32_t> m_strList;
//    try{
//        m_prxMotor->SensorWheelValue(m_strList);
//    }catch(Ice::Exception& e)
//    {
//        qDebug()<<"Error:"<<e.what();
//    }
//    for(int i = 0;i < m_strList.size();i++){
//        std::string str = m_strList.at(i);
//        m_data.append(str.c_str());
//    }
//    emit sig_sensorWheelInfo(m_data);
}
//===========led========================
void TMMotorWorker::slot_ledHeadEye(int nIndexF, int nIndexB)
{
    try{
        m_prxMotor->HeadEye(nIndexF,nIndexB);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_ledHeadEye2(int nDelay, bool nR, bool nG, bool nB)
{
    try{
        m_prxMotor->HeadEye2(nDelay,nR,nG,nB);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_ledHeadEar(int nDelay, bool nR, bool nG, bool nB)
{
    try{
        m_prxMotor->HeadEar(nDelay,nR,nG,nB);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_ledBodyLed(int nDelay, bool nR, bool nG, bool nB)
{
    try{
        m_prxMotor->BodyLed(nDelay,nR,nG,nB);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_ledTouchSet(bool bMode, int nColor, int nDelay)
{
    try{
        m_prxMotor->TouchSet(bMode,nColor,nDelay);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}
//============壁障=======================
void TMMotorWorker::slot_protectSet(bool bOpen)
{
    try{
        m_prxMotor->SetProtect(bOpen);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}

void TMMotorWorker::slot_protectState()
{
    try{
        bool m_bProtectState = m_prxMotor->GetProtect();
        emit sig_getProtectState(m_bProtectState);
    }catch(Ice::Exception& e)
    {
        qDebug()<<"Error:"<<e.what();
    }
}
